package com.mzy.tomcat.servlet;

import com.mzy.tomcat.http.MzyHttpRequest;
import com.mzy.tomcat.http.MzyHttpResponse;

import java.io.IOException;

public abstract class MzyHttpServlet implements Servlet {

    @Override
    public void init() {
        
    }

    @Override
    public void destroy() {

    }

    @Override
    public void service(MzyHttpRequest request, MzyHttpResponse response) throws IOException {
        String method = request.getMethod();

        if ("GET".equalsIgnoreCase(method)) {
            doGet(request, response);
        } else if ("POST".equalsIgnoreCase(method)) {
            doPost(request, response);
        } else if ("PUT".equalsIgnoreCase(method)) {
            doPut(request, response);
        } else if ("DELETE".equalsIgnoreCase(method)) {
            doDelete(request, response);
        }
    }

    private void doDelete(MzyHttpRequest request, MzyHttpResponse response) {

    }

    private void doPut(MzyHttpRequest request, MzyHttpResponse response) {

    }

    protected abstract void doPost(MzyHttpRequest request, MzyHttpResponse response) throws IOException;

    protected abstract void doGet(MzyHttpRequest request, MzyHttpResponse response) throws IOException;


}
